/**
 * 功能描述 导航栏
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper")
	var store =require("store");
	var planfile = require("../store/planfile");
	var activeUser = store.get("user");
	var subnavEvents = require("../handler/subnavEvents");
    var instance = {
        initComponent:function (params,widget){
        	var subnav=new Subnav({
        		parentNode:".J-subnav",
        		model:{
            		title:"团队入住登记",
            		items:[{
						id:"search",
						type: "search",
						placeholder: "组团单位/目的地",
						handler: function(str){
							aw.ajax({
								url: "api/checkinimplement/searchcheckin",
								data: {
									s: str,
									searchProperties: "groupReserve.planItemGroup.planItem.destination.name,groupReserve.planItemGroup.allianceOrg.name",
									"groupReserve.planItemGroup.checkInStatusIn":"Reserve,CheckIn",
									"servicePoint.pkServicePoint":activeUser.servicePoint.pkServicePoint,
									"dataSource":"GroupReserve",
		     						"status":"Confirmed",
									fetchProperties: planfile.fetchProperties
								},
								success: function(data){
									widget.get("grid").setData(data);
								}
							});
						}
            		},{
						id : "servicePoint",
						text : "服务点",
						tip : "服务点",
//						url:"api/servicepoint/operableservicepoints",
//						lazy:true,
						items:activeUser.privateServicePoints,
						type : "buttongroup",
						keyField : "pkServicePoint",
						valueField : "name",
						all: {
							show: false,
							position: "bottom"
						},
						handler:function(key,element){	
							widget.get("grid").refresh();
						}
            		},{
            			 id:"checkInStatus",
			   			 tip:"状态",
			   			 type:'buttongroup',
						 items:[{
							 	key :"Reserve",
								value:"待登记"
						 },{
								key :"CheckIn",
								value:"已登记"
						 },{
							 	key:"",
								value:"全部"
						 }],
            			handler:function(key,element){
            				var subnav = widget.get("subnav");
    						widget.get("grid").refresh({
    							"groupReserve.planItemGroup.checkInStatusIn" : key==""?"Reserve,CheckIn":(key=="Reserve"?"Reserve":"CheckIn"),
                            	"servicePoint":subnav.getValue("servicePoint"),
        						"groupReserve.reserveDate":subnav.getValue("reserveDate").start,
        						"groupReserve.reserveDateEnd":subnav.getValue("reserveDate").end,
         						"dataSource":"GroupReserve",
         						"status":"Confirmed",
         						"orderString" : "groupReserve.reserveDate,groupReserve.checkInDate",
         						fetchProperties: planfile.fetchProperties
    						});
    					}
            		},{
            			id:"reserveDate",
						tip:"预约日期",
						type:"daterange",
						ranges:{
	        				"今天": [moment().startOf("days"), moment().endOf("days")],
	 			            "本月": [moment().startOf("month"), moment().endOf("month")]
						},
						defaultRange: "本月",
						handler : function(time){
							widget.get("grid").refresh();
						}
            		},{
            			id:"save",
    					type:"button",
    					text:"登记完成",
    					show:false,
    					handler:function(){
    						widget.handler.subnav.saveAction(widget);
    					}
            		},{
            			id: "add",
            			type: "button",
            			text: "新增",
            			show:false,
            			handler:function(){
            				widget.get("signupgrid").setData([]);
            				widget.show([".J-signupgrid",".J-signupform"]).hide([".J-grid"]);
    						widget.get("subnav").show(["return","newsave"]).hide(["search", "add","servicePoint","checkInStatus","reserveDate"]);
    						widget.get("signupform").reset();
    						widget.get("signupgrid").setData([]);
            			}
            		},{
            			id:"newsave",
    					type:"button",
    					text:"保存",
    					show:false,
    					handler:function(){
    						subnavEvents.addSave(widget);
    					}
            		},{
            			id:"return",
    					type:"button",
    					text:"返回",
    					show:false,
    					handler:function(){
    						widget.handler.subnav.reback(widget);
    					}
            		}]
        		}
        	});
        	widget.set("subnav",subnav);

        }
    };
    module.exports = instance;
});
